/*
 * @(#)Tuple.java   1.0   May 10, 2007
 *
 * Copyright 2000-2007 ETH Zurich. All Rights Reserved.
 *
 * This software is the proprietary information of ETH Zurich.
 * Use is subject to license terms.
 *
 * @(#) $Id: Tuple.java 433 2007-05-22 12:45:58Z D\aldespin $
 */
package ch.ethz.globis.javaom.core;

import ch.ethz.globis.javaom.system.Metadata;

/**
 * @author aldespin
 * @version 1.0
 */
public class Tuple extends Object {

   private Object domain;
   private Object range;

   public Tuple(final Metadata metadata, final Object domain, final Object range) {
      super(metadata);
      this.setDomain(domain);
      this.setRange(range);
   }

   public Tuple(final Object domain, final Object range) {
      super();
      this.setDomain(domain);
      this.setRange(range);
      // TODO dress with object and tuple
      // this.dress(Metadata.METADATA.getTypeObject(Metadata.OBJECT));
      // this.dress(Metadata.METADATA.getTypeObject(Metadata.TUPLE));
   }

   public Object domain() {
      return this.domain;
   }

   public Object range() {
      return this.range;
   }

   public void setDomain(final Object domain) {
      this.domain = domain;
   }

   public void setRange(final Object range) {
      this.range = range;
   }

   /**
    * {@inheritDoc}
    */
   @Override
   public String toString() {
      final StringBuffer result = new StringBuffer();
      result.append("<tuple id=\"" + this.getID() + "\">");
      String key = Metadata.METADATA.getObjectKey(this.domain());
      if (key != null) {
         result.append("<domain><" + key + " id=\"" + this.domain().getID() + "\"/></domain>");
      } else {
         result.append("<domain><object id=\"" + this.domain().getID() + "\"/></domain>");
      }
      key = Metadata.METADATA.getObjectKey(this.range());
      if (key != null) {
         result.append("<range><" + key + " id=\"" + this.range().getID() + "\"/></range>");
      } else {
         result.append("<range><object id=\"" + this.range().getID() + "\"/></range>");
      }
      result.append("</tuple>");
      return result.toString();
   }
}
